package com.demo.base.redis;

import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * Created by ethan on 2017/2/11.
 */
public class ObjectRedisTemplate<V> extends RedisTemplate<String, V> {

    public ObjectRedisTemplate(
            RedisConnectionFactory connectionFactory,
            Jackson2JsonRedisSerializer<V> jsonRedisSerializer
    ) {
        StringRedisSerializer stringSerializer = new StringRedisSerializer();
        this.setKeySerializer(stringSerializer);
        this.setHashKeySerializer(stringSerializer);
        this.setValueSerializer(jsonRedisSerializer);
        this.setHashValueSerializer(jsonRedisSerializer);

        this.setConnectionFactory(connectionFactory);
        this.afterPropertiesSet();
    }
}
